﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMS.DataAccess.Trademark.BO;
using AMS.DataAccess.Trademark.BO.Enums;
using AMS.DataAccess.Trademark.Interfaces;
using System.Data;

public partial class Cases_ucEditTrademark : UCBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (CurrentAction == BusinessAction.UnKnown)
            {
                CurrentAction = BusinessAction.ActionNew;
            }
        }
    }

    public void EditTrademark(TrademarkInfo trademark)
    {
        txtApplyDate.Text = Utils.DateTimeToString(trademark.ApplyDate);
        txtApplyNumber.Text = trademark.ApplyNumber;
        txtClassAndItem.Text = trademark.Class;
        txtName.Text = trademark.Name;
        txtNameE.Text = trademark.NameE;
        txtNote.Text = trademark.Note;
        txtRegisterAddress.Text = trademark.RegisterAddress;
        txtRegisterDate.Text = Utils.DateTimeToString(trademark.RegisterDate);
        txtRegisterNumber.Text = trademark.RegisterNumber;
        txtRegisterUser.Text = trademark.RegisterUser;
        txtZipcode.Text = trademark.RegisterZipcode;
        drpStatus.SelectedValue = ((int)trademark.TrademarkStatus).ToString();

        CurrentAction = BusinessAction.ActionUpdate;
        SetItemID<int>(trademark.CustomerID);
    }

    public bool GetTrademark(TrademarkInfo trademark)
    {
        // TODO: validate the trademark
        trademark.ApplyNumber = txtApplyNumber.Text;
        trademark.Name = txtName.Text;
        trademark.NameE = txtNameE.Text;
        trademark.Note = txtNote.Text;
        trademark.RegisterAddress = txtRegisterAddress.Text;
        trademark.RegisterZipcode = txtZipcode.Text;
        trademark.RegisterNumber = txtRegisterNumber.Text;
        trademark.RegisterUser = txtRegisterUser.Text;
        trademark.TrademarkStatus = (TrademarkStatus)int.Parse(drpStatus.SelectedValue);

        if (txtApplyDate.Text != string.Empty)
        {
            trademark.ApplyDate = DateTime.Parse(txtApplyDate.Text);
        }

        if (txtRegisterDate.Text != string.Empty)
        {
            trademark.RegisterDate = DateTime.Parse(txtRegisterDate.Text);
        }

        if (CurrentAction == BusinessAction.ActionUpdate)
        {
            trademark.CustomerID = GetItemID<int>();
        }

        return true;
    }
}
